import DatabaseUtil from '../utils/DatabaseUtil';

class WeightConfigMapper {
  public STORE_ID = "CommunityConfigMapper";
  public KEY_OFFSET_STRING_ELEMENT: string = 'key_offset_string';
  public KEY_RATIO_STRING_ELEMENT: string = 'key_ratio_string';

  public getOffSet() {
    return DatabaseUtil.WeightConfigPreferences.get(this.KEY_OFFSET_STRING_ELEMENT, 0);
  }

  public putOffSet(value: number) {
    DatabaseUtil.WeightConfigPreferences.put(this.KEY_OFFSET_STRING_ELEMENT, value);
    return DatabaseUtil.WeightConfigPreferences.flush();
  }

  public getRatio() {
    return DatabaseUtil.WeightConfigPreferences.get(this.KEY_RATIO_STRING_ELEMENT, 0);
  }

  public PutRatio(value: number) {
    DatabaseUtil.WeightConfigPreferences.put(this.KEY_RATIO_STRING_ELEMENT, value);

    return DatabaseUtil.WeightConfigPreferences.flush((err, d) => {
      console.log(`anran err = ${JSON.stringify(err)} d = ${d}`)
    });
  }
}

export default new WeightConfigMapper();